﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class CategoryManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            load_AllCategory();
        }
    }

    public void load_AllCategory()
    {
        CategoryRepeater.DataSource = BusLogic.Category.get_ALL_CATEGORY();
        CategoryRepeater.DataBind();
    }

    protected void lbtDelete_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in CategoryRepeater.Items)
        {
            CheckBox cb = (CheckBox)item.FindControl("cbxCheckCategory");

            if (cb.Checked == true)
            {
                TextBox txtCategoryId = (TextBox)item.FindControl("txtCategoryId");
                BusLogic.Category.remove_CATEGORY(int.Parse(txtCategoryId.Text));
            }
        }
        load_AllCategory();
        cbxCheckALLCategory.Checked = false;
    }

    protected void cbxCheckALLCategory_CheckedChanged(object sender, EventArgs e)
    {
        if (cbxCheckALLCategory.Checked == true)
        {
            foreach (RepeaterItem item in CategoryRepeater.Items)
            {
                CheckBox cbxCheckCategory = item.FindControl("cbxCheckCategory") as CheckBox;
                cbxCheckCategory.Checked = true;
            }
        }
        else
        {
            foreach (RepeaterItem item in CategoryRepeater.Items)
            {
                CheckBox cbxCheckCategory = item.FindControl("cbxCheckCategory") as CheckBox;
                cbxCheckCategory.Checked = false;
            }
        }
        
    }
}
